<?php
class Model_DbTable_Tests extends HackerU_Db_Table
{
	public function load($id)
	{
		$cond = array('id' => (int)$id);
		$result = $this->select(array(), $cond);
		if($result){
			$result = $result[0];
		}
		return $result;
	}
	
	public function getTestDetails($id)
	{
		$id = (int)$id;
		$sql = "SELECT  tests.id as testId,
							tests.name,
							tests.subject,
							questions.id as qId,
							questions._desc as q,
							answers.id as ansId,
							answers._desc as ans
				 FROM tests
					INNER JOIN questions
								ON tests.id = questions.testId AND
						   			 tests.id = $id
					INNER JOIN answers
								ON questions.id = answers.questionId
				 WHERE tests.id = $id";
		return $this->fetchByQuery($sql);
	}
}